import { ConfigService } from "@nestjs/config";
import { TypeOrmModuleOptions } from "@nestjs/typeorm";

export const getDatabaseConfig = (
  configService: ConfigService
): TypeOrmModuleOptions => ({
  type: "mysql",
  host: configService.get<string>("DB_HOST", "localhost"),
  port: configService.get<number>("DB_PORT", 3306),
  username: configService.get<string>("DB_USERNAME", "root"),
  password: configService.get<string>("DB_PASSWORD", "123456"),
  database: configService.get("DB_NAME", "testdev"),
  synchronize: true, // 在生产环境中应该设置为false
  logging: true, // 开发环境开启SQL日志
  autoLoadEntities: true, // 自动加载实体
});
